<html>
<head><meta charset="utf-8"><title>two-phase borrows with existing loans · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html">two-phase borrows with existing loans</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="148375189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148375189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148375189">(Nov 26 2018 at 15:39)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Just chatted with <span class="user-mention" data-user-id="116118">@Matthew Jasper</span>, and I learned that we accept code like</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">two_phase_overlapping1</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vec</span><span class="o">!</span><span class="p">[];</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">p</span><span class="p">.</span><span class="n">len</span><span class="p">());</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>Can we, uh, not do that?^^ It would do quite horrible things to Stacked Borrows. Firstly, it'd kill the stack. More interestingly, to actually properly explain what happens (<span class="user-mention" data-user-id="126804">@Ariel Ben-Yehuda</span> came up with some way more crazy examples), we'd probably have to generalize from a stack to a tree or some such thing</p>



<a name="148375275"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148375275" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148375275">(Nov 26 2018 at 15:40)</a>:</h4>
<p>I think I have a fairly simple way of supporting two-phase borrows by immediately sharing the mutable reference, done. this works nicely together with the rule that <em>reading</em> from a mutable reference does not require popping of frozen/shared items.</p>



<a name="148375296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148375296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148375296">(Nov 26 2018 at 15:40)</a>:</h4>
<p>but code like the above breaks that idea completely</p>



<a name="148385841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148385841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148385841">(Nov 26 2018 at 18:13)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> hmm</p>



<a name="148385854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148385854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148385854">(Nov 26 2018 at 18:13)</a>:</h4>
<p>we <em>could</em></p>



<a name="148385863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148385863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148385863">(Nov 26 2018 at 18:13)</a>:</h4>
<p>I'm not opposed to doing so per se, just thinking about the schedule</p>



<a name="148385867"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148385867" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148385867">(Nov 26 2018 at 18:14)</a>:</h4>
<p>we might be able to get away with calling this a bug fix</p>



<a name="148385913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148385913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148385913">(Nov 26 2018 at 18:14)</a>:</h4>
<p>I guess we can still backport to Rust 2018</p>



<a name="148385919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148385919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148385919">(Nov 26 2018 at 18:14)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> can you file an issue?</p>



<a name="148393146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148393146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148393146">(Nov 26 2018 at 19:49)</a>:</h4>
<p>Hmm. The code is actually safe, isn't it? It feels wrong to go out of the way to disallow safe code; the point of NLL is to reduce false negatives.</p>



<a name="148394380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394380">(Nov 26 2018 at 20:06)</a>:</h4>
<p>well, that's the question, isn't it</p>



<a name="148394399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394399">(Nov 26 2018 at 20:07)</a>:</h4>
<p>that is, the code is not safe according to the stacked borrows rules that <span class="user-mention" data-user-id="120791">@RalfJ</span> has been working on, it's UB</p>



<a name="148394412"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394412" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394412">(Nov 26 2018 at 20:07)</a>:</h4>
<p>but the question then is whether this makes the rules wrong</p>



<a name="148394424"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394424" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394424">(Nov 26 2018 at 20:07)</a>:</h4>
<p>I'm inclined to try and tread carefully here</p>



<a name="148394529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394529">(Nov 26 2018 at 20:08)</a>:</h4>
<p>I'd still like to do <a href="https://github.com/rust-lang/rust/issues/53198" target="_blank" title="https://github.com/rust-lang/rust/issues/53198">this refactoring</a></p>



<a name="148394566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394566">(Nov 26 2018 at 20:09)</a>:</h4>
<p>which I think would also reject the example in question</p>



<a name="148394727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148394727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148394727">(Nov 26 2018 at 20:11)</a>:</h4>
<p>opened <a href="https://github.com/rust-lang/rust/issues/56254" target="_blank" title="https://github.com/rust-lang/rust/issues/56254">https://github.com/rust-lang/rust/issues/56254</a></p>



<a name="148395291"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395291" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395291">(Nov 26 2018 at 20:19)</a>:</h4>
<blockquote>
<p>this makes the rules wrong</p>
</blockquote>
<p>I think this is the crux for me — what is actually driving what Rust-the-language accepts? Is stacked borrows the true arbiter of what's safe?</p>



<a name="148395529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395529">(Nov 26 2018 at 20:23)</a>:</h4>
<p>it aims to be</p>



<a name="148395540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395540">(Nov 26 2018 at 20:23)</a>:</h4>
<p>we can of course decide that it should accept this code</p>



<a name="148395543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395543">(Nov 26 2018 at 20:23)</a>:</h4>
<p>there's a sort of balancing act</p>



<a name="148395548"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395548" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395548">(Nov 26 2018 at 20:23)</a>:</h4>
<p>how complex are the rules to describe</p>



<a name="148395560"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395560" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395560">(Nov 26 2018 at 20:23)</a>:</h4>
<p>(and understand)</p>



<a name="148395563"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395563" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395563">(Nov 26 2018 at 20:23)</a>:</h4>
<p>vs what code they accept</p>



<a name="148395575"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395575" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395575">(Nov 26 2018 at 20:23)</a>:</h4>
<p>(and what optimizations they permit)</p>



<a name="148395702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148395702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148395702">(Nov 26 2018 at 20:25)</a>:</h4>
<p>As an outsider, it's interesting because it seems like stacked borrows is a post-hoc justification of what "the code" does. This makes it weird when the code is adjusted to fit the model (physicists everywhere are jealous)</p>



<a name="148399247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399247">(Nov 26 2018 at 21:24)</a>:</h4>
<blockquote>
<p>As an outsider, it's interesting because it seems like stacked borrows is a post-hoc justification of what "the code" does. This makes it weird when the code is adjusted to fit the model (physicists everywhere are jealous)</p>
</blockquote>
<p>stacked borrows is a post-hoc justification of original borrowck and might serve as a guide for future borrowck evolution. also, it might uncover situations where borrowck is inconsistent or runs afoul of guarantees we might want to have. in this concrete case, for example, whether or not we allow such code has influence on how hard it will be for an optimization pass to analyze which shared reference can alias a given mutable reference.</p>



<a name="148399254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399254">(Nov 26 2018 at 21:24)</a>:</h4>
<p>but mostly, I'd like us to be able to <em>have that discussion</em></p>



<a name="148399260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399260">(Nov 26 2018 at 21:24)</a>:</h4>
<p>and that means not stabilizing too much too early</p>



<a name="148399511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399511">(Nov 26 2018 at 21:29)</a>:</h4>
<p>physicists model an immutable reality, whereas modelling programming languages can hopefully contribute to improve the future evolution of that language ;)</p>



<a name="148399568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Keith Yeung <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399568">(Nov 26 2018 at 21:30)</a>:</h4>
<p>think HTML but with a lot more formal verification :)</p>



<a name="148399585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Keith Yeung <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399585">(Nov 26 2018 at 21:30)</a>:</h4>
<p>and of course, without the backwards compatibility issues</p>



<a name="148399597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148399597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148399597">(Nov 26 2018 at 21:30)</a>:</h4>
<p>I'd actually claim that doing formal models during development will often lead to a better understanding of what is being developed, and thus a better language</p>



<a name="148403361"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148403361" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148403361">(Nov 26 2018 at 22:28)</a>:</h4>
<p>looks <span class="user-mention" data-user-id="120791">@RalfJ</span> like this <em>might</em> be a small diff</p>



<a name="148403364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148403364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148403364">(Nov 26 2018 at 22:28)</a>:</h4>
<p>I guess we'll see what errors I get</p>



<a name="148404220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404220">(Nov 26 2018 at 22:40)</a>:</h4>
<p>hmm, I get a bunch :)</p>



<a name="148404224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404224">(Nov 26 2018 at 22:40)</a>:</h4>
<p>from the match desugaring, I think</p>



<a name="148404307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404307">(Nov 26 2018 at 22:41)</a>:</h4>
<p>ah, yes</p>



<a name="148404376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404376">(Nov 26 2018 at 22:42)</a>:</h4>
<p>I have to check, <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> might remember better, but I believe we are relying on the current behavior in match desugaring -- we create shared borrows of the various "discriminants" that we examine</p>



<a name="148404382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404382">(Nov 26 2018 at 22:42)</a>:</h4>
<p>then we make two-phase borrows for <code>ref mut</code> bindings</p>



<a name="148404390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404390">(Nov 26 2018 at 22:42)</a>:</h4>
<p>but they are not activated until we enter the arm</p>



<a name="148404419"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404419" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404419">(Nov 26 2018 at 22:43)</a>:</h4>
<p>some of those have the peculiar characteristic that they are 2PB that <em>never</em> get activated</p>



<a name="148404904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148404904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148404904">(Nov 26 2018 at 22:51)</a>:</h4>
<p>We also create borrows of the places that we bind variables to, which is the more difficult one to fix, since they don't have a different borrow kind.</p>



<a name="148405029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148405029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148405029">(Nov 26 2018 at 22:53)</a>:</h4>
<p>I'll try to write up what I think is the best solution (with the time we have) tomorrow.</p>



<a name="148623123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148623123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148623123">(Nov 27 2018 at 08:00)</a>:</h4>
<p>So the simplest thing that I think we can do is to add another borrow kind that doesn't conflict with reservations, but is otherwise a shared borrow. Then move all fake borrows to that kind (shallow borrows aren't compatible with niche layout optimisations) and remove the shallow borrow kind. <br>
This would also allow us to do all post NLL cleanup in a single pass (we wouldn't backport that part).</p>



<a name="148623253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148623253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148623253">(Nov 27 2018 at 08:03)</a>:</h4>
<p>Having a different borrow kind isn't great, but fake borrows are strange and special anyway.</p>



<a name="148623379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148623379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148623379">(Nov 27 2018 at 08:06)</a>:</h4>
<blockquote>
<p>some of those have the peculiar characteristic that they are 2PB that <em>never</em> get activated</p>
</blockquote>
<p>They are activated as long as the arm is reachable, which doesn't seem any different to function call two phase borrows.</p>



<a name="148628950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148628950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148628950">(Nov 27 2018 at 10:12)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> what would be an example of a desugared match guard that relies on the existing-loans-are-preserved thing?</p>



<a name="148629344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148629344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148629344">(Nov 27 2018 at 10:22)</a>:</h4>
<p>Any match that has a mut ref binding with a match guard.</p>



<a name="148631912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148631912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148631912">(Nov 27 2018 at 11:22)</a>:</h4>
<p>okay so let's say we have</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">foo</span><span class="p">(</span><span class="n">x</span>: <span class="nb">Option</span><span class="o">&lt;</span><span class="nb">String</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">  </span><span class="k">match</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="nb">Some</span><span class="p">(</span><span class="k">mut</span><span class="w"> </span><span class="k">ref</span><span class="w"> </span><span class="n">s</span><span class="p">)</span><span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">starts_with</span><span class="p">(</span><span class="s">&quot;hello&quot;</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">s</span><span class="p">.</span><span class="n">push_str</span><span class="p">(</span><span class="s">&quot; world!&quot;</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="n">_</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">  </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>what does this desugar to, with the fake refs?</p>



<a name="148632683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632683">(Nov 27 2018 at 11:41)</a>:</h4>
<p>@RalfJ so the problem is a conflict with the "borrow lock"</p>



<a name="148632690"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632690" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632690">(Nov 27 2018 at 11:41)</a>:</h4>
<p>*the "discriminant lock" borrow</p>



<a name="148632693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632693">(Nov 27 2018 at 11:42)</a>:</h4>
<p>which borrows <code>x</code> immutably for the duration of the arms</p>



<a name="148632737"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632737" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632737">(Nov 27 2018 at 11:42)</a>:</h4>
<p>(to prevent it from being modified in a way that breaks exhaustiveness)</p>



<a name="148632745"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632745" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632745">(Nov 27 2018 at 11:42)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="n">_fake1</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">shallow</span><span class="w"> </span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="n">_fake2</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nb">Some</span><span class="p">).</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="c1">// switch on discriminant</span>
<span class="n">s_for_guard</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="p">(</span><span class="n">x</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="nb">Some</span><span class="p">).</span><span class="mi">0</span><span class="p">;</span><span class="w"></span>
<span class="n">s_for_guard_ref</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">s_for_guard</span><span class="p">;</span><span class="w"></span>
<span class="c1">// guard, using *s_for_guard_ref instead of s</span>
<span class="n">FakeRead</span><span class="p">(</span><span class="n">_fake1</span><span class="p">);</span><span class="w"></span>
<span class="n">FakeRead</span><span class="w"> </span><span class="p">(</span><span class="n">_fake2</span><span class="p">);</span><span class="w"></span>
<span class="n">s</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">s_for_guard</span><span class="p">;</span><span class="w"></span>
<span class="c1">// Arm as usual</span>
</pre></div>



<a name="148632759"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632759" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632759">(Nov 27 2018 at 11:43)</a>:</h4>
<p>yea that</p>



<a name="148632851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148632851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148632851">(Nov 27 2018 at 11:45)</a>:</h4>
<p>Everything involving _fakeN is deleted shortly after NLL</p>



<a name="148643910"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148643910" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148643910">(Nov 27 2018 at 15:13)</a>:</h4>
<blockquote>
<p>Having a different borrow kind isn't great, but fake borrows are strange and special anyway.</p>
</blockquote>
<p>this is what I was thinking</p>



<a name="148643922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148643922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148643922">(Nov 27 2018 at 15:13)</a>:</h4>
<p>for one thing, these "borrow locks" are different in kind from other borrows</p>



<a name="148643930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148643930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148643930">(Nov 27 2018 at 15:13)</a>:</h4>
<p>hmm, well, are they?</p>



<a name="148643941"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148643941" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148643941">(Nov 27 2018 at 15:14)</a>:</h4>
<p>I think they are -- or at least <em>could be</em></p>



<a name="148644015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148644015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148644015">(Nov 27 2018 at 15:14)</a>:</h4>
<p>That is, they are there to enforce rules about what you can/can't do in match arms, guards, etc, because of our exhaustiveness rules. It potentially creates UB to violate those rules because you mess up our match desugaring.</p>



<a name="148644022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148644022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148644022">(Nov 27 2018 at 15:14)</a>:</h4>
<p>However, it's not clear that <strong>stacked borrows</strong> cares about this</p>



<a name="148644046"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148644046" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148644046">(Nov 27 2018 at 15:14)</a>:</h4>
<p>that is, if you used unsafe code to violate those loans, this may create UB, but not necessarily because of an aliasing violation</p>



<a name="148644074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148644074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148644074">(Nov 27 2018 at 15:15)</a>:</h4>
<p>(it's more akin to creating UB by relying on the layout of a struct or some such thing, which we are free to change)</p>



<a name="148644101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148644101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148644101">(Nov 27 2018 at 15:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> did you do any work on that?</p>



<a name="148651932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148651932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148651932">(Nov 27 2018 at 17:04)</a>:</h4>
<p>I've done no work on this yet since I've been traveling. I should be able to get this done tonight if you don't want to take it.</p>



<a name="148657686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148657686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148657686">(Nov 27 2018 at 18:25)</a>:</h4>
<p>I've not done anything, not feeling well today. Probably shoudn't be typing here now I'm supposed to be sleeping :P</p>



<a name="148663089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148663089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> memoryruins <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148663089">(Nov 27 2018 at 19:52)</a>:</h4>
<p>using the original example, if i try to push twice, it errors with </p>
<div class="codehilite"><pre><span></span><span class="n">error</span><span class="p">[</span><span class="n">E0502</span><span class="p">]</span>: <span class="nc">cannot</span><span class="w"> </span><span class="n">borrow</span><span class="w"> </span><span class="err">`</span><span class="n">x</span><span class="err">`</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">mutable</span><span class="w"> </span><span class="n">because</span><span class="w"> </span><span class="n">it</span><span class="w"> </span><span class="n">is</span><span class="w"> </span><span class="n">also</span><span class="w"> </span><span class="n">borrowed</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">immutable</span><span class="w"></span>
<span class="w"> </span><span class="o">-</span>-&gt; <span class="nc">src</span><span class="o">/</span><span class="n">lib</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">4</span>:<span class="mi">5</span><span class="w"></span>
<span class="w">  </span><span class="o">|</span><span class="w"></span>
<span class="mi">3</span><span class="w"> </span><span class="o">|</span><span class="w">     </span><span class="kd">let</span><span class="w"> </span><span class="n">p</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="n">x</span><span class="p">;</span><span class="w"></span>
<span class="w">  </span><span class="o">|</span><span class="w">             </span><span class="o">--</span><span class="w"> </span><span class="n">immutable</span><span class="w"> </span><span class="n">borrow</span><span class="w"> </span><span class="n">occurs</span><span class="w"> </span><span class="n">here</span><span class="w"></span>
<span class="mi">4</span><span class="w"> </span><span class="o">|</span><span class="w">     </span><span class="n">x</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">p</span><span class="p">.</span><span class="n">len</span><span class="p">());</span><span class="w"></span>
<span class="w">  </span><span class="o">|</span><span class="w">     </span><span class="o">^^^^^^^^^^^^^^^</span><span class="w"> </span><span class="n">mutable</span><span class="w"> </span><span class="n">borrow</span><span class="w"> </span><span class="n">occurs</span><span class="w"> </span><span class="n">here</span><span class="w"></span>
<span class="mi">5</span><span class="w"> </span><span class="o">|</span><span class="w">     </span><span class="n">x</span><span class="p">.</span><span class="n">push</span><span class="p">(</span><span class="n">p</span><span class="p">.</span><span class="n">len</span><span class="p">());</span><span class="w"></span>
<span class="w">  </span><span class="o">|</span><span class="w">            </span><span class="o">-</span><span class="w"> </span><span class="n">immutable</span><span class="w"> </span><span class="n">borrow</span><span class="w"> </span><span class="n">later</span><span class="w"> </span><span class="n">used</span><span class="w"> </span><span class="n">here</span><span class="w"></span>
</pre></div>


<p>(posting ^ if it gives a bigger picture / current diagnostics. if I push once and debug print x, it works, printing <code>[0]</code>)</p>



<a name="148673170"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148673170" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148673170">(Nov 27 2018 at 22:29)</a>:</h4>
<p>Ugh, we need Shallow borrows to allow matching on <code>(*x).1</code> while <code>(*x).0</code> is borrowed.</p>



<a name="148677017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148677017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148677017">(Nov 27 2018 at 23:37)</a>:</h4>
<p>{WIP] PR <a href="https://github.com/rust-lang/rust/pull/56301" target="_blank" title="https://github.com/rust-lang/rust/pull/56301">https://github.com/rust-lang/rust/pull/56301</a>. Thinking about this some more, I'm not convinced that 2 phase borrows are the correct way of handling match guards at all. Notably, in <code>match x { ref mut z if ...</code>, <code>x</code> should be mutably borrowed for the guard, as well as for the match arm.</p>



<a name="148696267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148696267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148696267">(Nov 28 2018 at 08:10)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> I assume the <code>&amp;mut</code> there is an <code>&amp;mut2phase</code>?</p>



<a name="148696440"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148696440" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148696440">(Nov 28 2018 at 08:14)</a>:</h4>
<p><span class="user-mention" data-user-id="126804">@Ariel Ben-Yehuda</span> <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> See <a href="https://github.com/rust-lang/rust/issues/56254#issuecomment-442357546" target="_blank" title="https://github.com/rust-lang/rust/issues/56254#issuecomment-442357546">https://github.com/rust-lang/rust/issues/56254#issuecomment-442357546</a>: I don't understand why my desugaring based on transmute does not work. All pointer addresses are the same, from what I can see.</p>



<a name="148696601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148696601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148696601">(Nov 28 2018 at 08:18)</a>:</h4>
<blockquote>
<p>x should be mutably borrowed for the guard, as well as for the match arm.</p>
</blockquote>
<p>by "mutably borrowed" you mean there should be an active mutable loan?</p>



<a name="148696748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148696748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148696748">(Nov 28 2018 at 08:22)</a>:</h4>
<p>Yes.</p>



<a name="148696757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148696757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148696757">(Nov 28 2018 at 08:23)</a>:</h4>
<p>Anyway, i think i have a way to avoid 2PB for matches.</p>



<a name="148697047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148697047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148697047">(Nov 28 2018 at 08:31)</a>:</h4>
<p>Is that included in your PR above?</p>



<a name="148698356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148698356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148698356">(Nov 28 2018 at 09:03)</a>:</h4>
<p>I now have an implementation of two-phase borrows <em>without</em> existing loans. It <a href="https://github.com/solson/miri/compare/rustup...RalfJung:stacked-borrows-2-phase" target="_blank" title="https://github.com/solson/miri/compare/rustup...RalfJung:stacked-borrows-2-phase">is trivial, as expected</a>: When retagging for an <code>&amp;mut2phase</code>, after doing the usual retag business, we simply immediately do a shared re-borrow of the mutable borrow we just created. done.</p>



<a name="148698415"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148698415" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148698415">(Nov 28 2018 at 09:04)</a>:</h4>
<p>No, it's a different approach. I'm still thinking it through.</p>



<a name="148698423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148698423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148698423">(Nov 28 2018 at 09:04)</a>:</h4>
<p>We do not have to rewrite the other uses, because <em>read</em> uses of something shared do not invalidate mutable references that are ancestors of the shared one</p>



<a name="148698443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148698443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148698443">(Nov 28 2018 at 09:05)</a>:</h4>
<p>as in, <code>let x = &amp;mut 2; let y = &amp;*x; let _val1 = *x; let _val2 = *y;</code> is fine because reading through <code>x</code> does not invalidate <code>y</code></p>



<a name="148698484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148698484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148698484">(Nov 28 2018 at 09:06)</a>:</h4>
<p>that also applies "further up the chain":</p>
<div class="codehilite"><pre><span></span>let x = &amp;mut 42;
let y = &amp;mut*x;
let z = &amp;*y;
let _val1 = *x;
let _val2 = *y;
</pre></div>


<p>would be fine if it was accepted, because  reading <code>x</code> is justified by <code>z</code>, and hence does not have to invalidate <code>y</code></p>



<a name="148698566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148698566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148698566">(Nov 28 2018 at 09:08)</a>:</h4>
<p>This works quite nicely for 2phase borrows (they are only a tiny extension of the model), but it enforces that there be no outstanding references when the 2phase borrow starts.</p>



<a name="148712963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148712963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148712963">(Nov 28 2018 at 14:02)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> the transmute based desugaring was one of the first things we thought of, but 2PB seemed more elegant.</p>



<a name="148713074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148713074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148713074">(Nov 28 2018 at 14:04)</a>:</h4>
<p>(IIRC)</p>



<a name="148713079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148713079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148713079">(Nov 28 2018 at 14:04)</a>:</h4>
<p>I'll have to catch up on the comments though</p>



<a name="148713090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148713090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148713090">(Nov 28 2018 at 14:04)</a>:</h4>
<p>I'm still feeling sort of sick today :( not sure how much I'll be up for working yet</p>



<a name="148713216"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148713216" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148713216">(Nov 28 2018 at 14:06)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> out of curiosity, when you said: </p>
<blockquote>
<p>Notably, in <code>match x { ref mut z if ...</code>, <code>x</code> should be mutably borrowed for the guard, as well as for the match arm.</p>
</blockquote>
<p>what was the scenario that you are concerned about?</p>
<p>Unless I'm mistaken, the semantics for references to pattern variables in guards should prevent any mutable accesses from occurring... and therefore the mutable borrow need not be activated during the guard's execution, no?</p>



<a name="148713231"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148713231" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148713231">(Nov 28 2018 at 14:07)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> I don't quite follow why using 2PB is wrong for match guards though, <em>particularly</em> if we manage to move to the model <span class="user-mention" data-user-id="120791">@RalfJ</span> is advocating. If I understand that means that a 2PB is equivalent to a <code>&amp;mut</code> which is reborrowed to an <code>&amp;</code>, right? (And the activation corresponds to the <code>&amp;</code> going out of scope)</p>
<p>In that case, in the example:</p>
<blockquote>
<p><code>match x { ref mut z if ...</code></p>
</blockquote>
<p>I believe we would create a 2PB on <code>z</code>, so there <em>would</em> be an active mut borrow on <code>x</code>? (But one that is itself frozen)</p>
<p>I'm also not sure why it matters if there is one =)</p>



<a name="148713246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148713246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148713246">(Nov 28 2018 at 14:07)</a>:</h4>
<p>(jinx)</p>



<a name="148718697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148718697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148718697">(Nov 28 2018 at 15:23)</a>:</h4>
<blockquote>
<p>If I understand that means that a 2PB is equivalent to a &amp;mut which is reborrowed to an &amp;, right? (And the activation corresponds to the &amp; going out of scope)</p>
</blockquote>
<p>Yes. Crucially, rewriting uses is <em>not</em> necessary, any read-only use of a variable that is a parent of the <code>&amp;mut</code> can still be read from (this is unlike my original thoughts from months ago where I thought we'd also have to rewrite uses)</p>



<a name="148718807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148718807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148718807">(Nov 28 2018 at 15:24)</a>:</h4>
<p>the problem with the current version is that it creates a new borrow but keeps the old ones alive "in parallel", so we have a tree more than a stack. a tree might be sound, might even be closer to what one needs to model LLVM's noalias, but it is much more complicated -- and everything except for this quirk in 2PB can be explained by just a stack.</p>



<a name="148719032"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148719032" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148719032">(Nov 28 2018 at 15:28)</a>:</h4>
<blockquote>
<p>don't quite follow why using 2PB is wrong for match guards though, particularly if we manage to move to the model @RalfJ is advocating.</p>
</blockquote>
<p>that doesn't seem possible though? the desugaring inherently relies on outstanding shared borrows remaining intact. the PR by <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> introduces a new kind of borrow that will not conflict and makes sure those all disappear before we execute anything, but that's quite a hack. it means giving a semantics to the MIR that the analysis actually happens on <em>still</em> requires trees. it solves miri's problem, but it doesn't solve the problem of giving a proper spec to MIR -- to all variants of MIR, including the one NLL runs on.</p>



<a name="148719074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148719074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148719074">(Nov 28 2018 at 15:28)</a>:</h4>
<blockquote>
<p>the transmute based desugaring was one of the first things we thought of, but 2PB seemed more elegant.</p>
</blockquote>
<p>you clearly have different taste than I do.  :D or maybe you weren't aware that the transmute is actually generally sound, not just in some special cases?</p>



<a name="148720056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148720056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148720056">(Nov 28 2018 at 15:41)</a>:</h4>
<p>I am aware of that</p>



<a name="148721557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148721557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148721557">(Nov 28 2018 at 15:52)</a>:</h4>
<p>kk</p>



<a name="148723247"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148723247" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148723247">(Nov 28 2018 at 16:16)</a>:</h4>
<blockquote>
<p>it means giving a semantics to the MIR that the analysis actually happens on <em>still</em> requires trees. </p>
</blockquote>
<p>ok, so you're saying that if we:</p>
<ul>
<li>create shallow borrows and whatever we need to "lock down" the thing we are matching on</li>
<li>create <code>&amp;&amp;T</code> for bindings in a guard and then transmute to <code>&amp;&amp;mut T</code> </li>
<li>and then once we enter an arm create the proper <code>ref mut</code></li>
</ul>
<p>and hence just avoid 2PB in this desugaring at all, we just don't have any particular problems.</p>
<p>I think I agree with that.</p>



<a name="148723252"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148723252" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148723252">(Nov 28 2018 at 16:16)</a>:</h4>
<p>(Sound correct <span class="user-mention" data-user-id="120791">@RalfJ</span> ?)</p>



<a name="148723916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148723916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148723916">(Nov 28 2018 at 16:26)</a>:</h4>
<blockquote>
<p>Yes. Crucially, rewriting uses is <em>not</em> necessary, any read-only use of a variable that is a parent of the <code>&amp;mut</code> can still be read from (this is unlike my original thoughts from months ago where I thought we'd also have to rewrite uses)</p>
</blockquote>
<p>But I definitely need to work this through in my head to fully understand.</p>
<p>Thinking about it a bit more, I think the way the code is treating a 2PB now is roughly like an "upgradable read lock". That is, the initial borrow is shared, and then it is "activated" into an <code>&amp;mut</code>. (But this activation is not presently explicit in the MIR, though we always know what it is.)</p>
<p>This also feels coherent but it still feels prudent to be more conservative for now.</p>



<a name="148724224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148724224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148724224">(Nov 28 2018 at 16:30)</a>:</h4>
<blockquote>
<p>(Sound correct <span class="user-mention" data-user-id="120791">@RalfJ</span> ?)</p>
</blockquote>
<p>yes</p>



<a name="148724304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148724304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148724304">(Nov 28 2018 at 16:31)</a>:</h4>
<blockquote>
<p>Thinking about it a bit more, I think the way the code is treating a 2PB now is roughly like an "upgradable read lock". That is, the initial borrow is shared, and then it is "activated" into an &amp;mut. (But this activation is not presently explicit in the MIR, though we always know what it is.)</p>
</blockquote>
<p>Hm, I see. Yeah Stacked Borrows is not currently prepared for a borrow to change its "type" (unique/shared)</p>



<a name="148724389"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148724389" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148724389">(Nov 28 2018 at 16:32)</a>:</h4>
<p>I think doing that would require tracking the relationship of shared references more precisely, which would probably also need a tree.</p>



<a name="148727528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148727528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148727528">(Nov 28 2018 at 17:15)</a>:</h4>
<p>I'm not saying 2PB is <em>unsound</em> for match guards. I just don't think that it should be: allowing <code>match x { ref mut z if x == 1 =&gt; ...</code> is unexpected.</p>



<a name="148729710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148729710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148729710">(Nov 28 2018 at 17:48)</a>:</h4>
<p><code>x == z</code> seems even more unexpected</p>



<a name="148729723"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148729723" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148729723">(Nov 28 2018 at 17:48)</a>:</h4>
<p>that is "using" two mutable references to the same location</p>



<a name="148732686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148732686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148732686">(Nov 28 2018 at 18:36)</a>:</h4>
<p>my sense is we won't be able to change this for the initial Rust 2018 release</p>



<a name="148732698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148732698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148732698">(Nov 28 2018 at 18:36)</a>:</h4>
<p>but we might be able to make changes here for the follow-on release, presuming low impact (as seems likely)</p>



<a name="148732704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148732704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148732704">(Nov 28 2018 at 18:36)</a>:</h4>
<p>the clock is just running down</p>



<a name="148733710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148733710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148733710">(Nov 28 2018 at 18:49)</a>:</h4>
<p>That's probably the case.</p>



<a name="148740784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148740784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148740784">(Nov 28 2018 at 20:29)</a>:</h4>
<p>if only I had been two weeks faster :(</p>



<a name="148747500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747500">(Nov 28 2018 at 22:03)</a>:</h4>
<p>something that occurs to me, <span class="user-mention" data-user-id="116083">@pnkfelix</span> <span class="user-mention" data-user-id="116118">@Matthew Jasper</span> <span class="user-mention" data-user-id="120791">@RalfJ</span>, is that if we don't backport -- and I'm still not that keen on doing so because of the risk factor --</p>



<a name="148747502"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747502" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747502">(Nov 28 2018 at 22:03)</a>:</h4>
<p>we still have NLL-sound things to land anyway</p>



<a name="148747505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747505">(Nov 28 2018 at 22:03)</a>:</h4>
<p>we can make a warning period here if we have to</p>



<a name="148747553"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747553" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747553">(Nov 28 2018 at 22:04)</a>:</h4>
<p>there is already a kind of "NLL transition" taking place</p>



<a name="148747556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747556">(Nov 28 2018 at 22:04)</a>:</h4>
<p>and it feels like we can fit this into that</p>



<a name="148747561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747561">(Nov 28 2018 at 22:04)</a>:</h4>
<p>it's a bit different, of course, but so what</p>



<a name="148747578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747578">(Nov 28 2018 at 22:04)</a>:</h4>
<blockquote>
<p>we still have NLL-sound things to land anyway</p>
</blockquote>
<p>what does that means? soundness holes in NLL that must be fixed?</p>



<a name="148747593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747593">(Nov 28 2018 at 22:04)</a>:</h4>
<p>yes, there are some known soundness holes</p>



<a name="148747601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747601">(Nov 28 2018 at 22:05)</a>:</h4>
<p>mostly around user-supplied type annotations though</p>



<a name="148747612"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747612" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747612">(Nov 28 2018 at 22:05)</a>:</h4>
<p>things judged to be pretty edge-casey</p>



<a name="148747621"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747621" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747621">(Nov 28 2018 at 22:05)</a>:</h4>
<p><a href="https://discordapp.com/channels/442252698964721669/443148319431065610/517459924247117824" target="_blank" title="https://discordapp.com/channels/442252698964721669/443148319431065610/517459924247117824">link to conversation with <span class="user-mention" data-user-id="121055">@Pietro Albini</span> on discord</a></p>



<a name="148747698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148747698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148747698">(Nov 28 2018 at 22:06)</a>:</h4>
<p>Personally, I'm leaning against backporting</p>



<a name="148748158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748158">(Nov 28 2018 at 22:15)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> looking at the code in question from the new error:</p>
<div class="codehilite"><pre><span></span><span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">next</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="kd">let</span><span class="w"> </span><span class="n">val</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">llvm</span>::<span class="n">get_param</span><span class="p">(</span><span class="n">bx</span><span class="p">.</span><span class="n">llfn</span><span class="p">(),</span><span class="w"> </span><span class="o">*</span><span class="n">idx</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="n">c_uint</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="o">*</span><span class="n">idx</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">            </span><span class="n">val</span><span class="w"></span>
<span class="w">        </span><span class="p">};</span><span class="w"></span>
<span class="w">        </span><span class="k">match</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">mode</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="n">PassMode</span>::<span class="n">Ignore</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{},</span><span class="w"></span>
<span class="w">            </span><span class="n">PassMode</span>::<span class="n">Pair</span><span class="p">(..)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">OperandValue</span>::<span class="n">Pair</span><span class="p">(</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="n">next</span><span class="p">()).</span><span class="n">store</span><span class="p">(</span><span class="n">bx</span><span class="p">,</span><span class="w"> </span><span class="n">dst</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="n">PassMode</span>::<span class="n">Indirect</span><span class="p">(</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">_</span><span class="p">))</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="n">OperandValue</span>::<span class="n">Ref</span><span class="p">(</span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="n">next</span><span class="p">()),</span><span class="w"> </span><span class="bp">self</span><span class="p">.</span><span class="n">layout</span><span class="p">.</span><span class="n">align</span><span class="p">.</span><span class="n">abi</span><span class="p">).</span><span class="n">store</span><span class="p">(</span><span class="n">bx</span><span class="p">,</span><span class="w"> </span><span class="n">dst</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">            </span><span class="n">PassMode</span>::<span class="n">Direct</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">PassMode</span>::<span class="n">Indirect</span><span class="p">(</span><span class="n">_</span><span class="p">,</span><span class="w"> </span><span class="nb">None</span><span class="p">)</span><span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="n">PassMode</span>::<span class="n">Cast</span><span class="p">(</span><span class="n">_</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">                </span><span class="bp">self</span><span class="p">.</span><span class="n">store</span><span class="p">(</span><span class="n">bx</span><span class="p">,</span><span class="w"> </span><span class="n">next</span><span class="p">(),</span><span class="w"> </span><span class="n">dst</span><span class="p">);</span><span class="w"></span>
<span class="w">            </span><span class="p">}</span><span class="w"></span>
<span class="w">        </span><span class="p">}</span><span class="w"></span>
</pre></div>



<a name="148748167"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748167" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748167">(Nov 28 2018 at 22:15)</a>:</h4>
<p>with the error:</p>
<div class="codehilite"><pre><span></span>error[E0502]: cannot borrow `*bx` as mutable because it is also borrowed as immutable_codegen_llvm
   --&gt; src/librustc_codegen_llvm/abi.rs:279:28
    |
265 |         let mut next = || {
    |                        -- immutable borrow occurs here
266 |             let val = llvm::get_param(bx.llfn(), *idx as c_uint);
    |                                       -- first borrow occurs due to use of `bx` in closure
...
279 |                 self.store(bx, next(), dst);
    |                            ^^  ---- immutable borrow later used here
    |                            |
    |                            mutable borrow occurs here

error: aborting due to previous error
</pre></div>



<a name="148748193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748193">(Nov 28 2018 at 22:16)</a>:</h4>
<p>is the <code>bx</code> here a 2pb?</p>



<a name="148748233"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748233" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748233">(Nov 28 2018 at 22:16)</a>:</h4>
<p>Yes</p>



<a name="148748237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748237">(Nov 28 2018 at 22:16)</a>:</h4>
<p>sorry, which one, the <code>bx.llfn()</code>?</p>



<a name="148748241"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748241" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748241">(Nov 28 2018 at 22:16)</a>:</h4>
<p>the <code>self.store(bx, ...)</code>?</p>



<a name="148748246"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748246" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748246">(Nov 28 2018 at 22:16)</a>:</h4>
<p>if the latter, I .. feel a bit surprised, because I thought we didn't do it in that scenario.</p>



<a name="148748260"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748260" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748260">(Nov 28 2018 at 22:16)</a>:</h4>
<p>the former seems wrong because it is <code>fn llfn(&amp;self)</code></p>



<a name="148748293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748293">(Nov 28 2018 at 22:17)</a>:</h4>
<p>I guess we extended to fn arguments?</p>



<a name="148748364"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748364" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748364">(Nov 28 2018 at 22:18)</a>:</h4>
<p>I see, we do. Well... I was wrong about <em>that</em></p>



<a name="148748368"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748368" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748368">(Nov 28 2018 at 22:18)</a>:</h4>
<p>interesting</p>



<a name="148748385"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748385" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748385">(Nov 28 2018 at 22:18)</a>:</h4>
<p>(I thought we did only method receivers and binary operators)</p>



<a name="148748426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748426">(Nov 28 2018 at 22:19)</a>:</h4>
<p>( ok, we definitely have to prioritize also writing up a complete NLL document :) which has been on my mind for some time anyway... but the match desugaring discussion and now this brought it to the fore again )</p>



<a name="148748893"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748893" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748893">(Nov 28 2018 at 22:28)</a>:</h4>
<p>OK, I'll try to write up the current state and our long-term options tomorrow, since we should have time to implement them.</p>



<a name="148748978"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148748978" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148748978">(Nov 28 2018 at 22:29)</a>:</h4>
<p>Well, consensus from the release discussion was that a backport is off the table, which gives us a bit more time to settle on the <em>right</em> fix. I feel good about that.</p>



<a name="148749059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148749059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148749059">(Nov 28 2018 at 22:30)</a>:</h4>
<p>sure doing a backport to the Rust 2018 release doesn't look like the best idea</p>



<a name="148749068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148749068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148749068">(Nov 28 2018 at 22:30)</a>:</h4>
<p>we'll probably have to release a patch edition anyway</p>



<a name="148749071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148749071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Ariel Ben-Yehuda <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148749071">(Nov 28 2018 at 22:31)</a>:</h4>
<p>for NLL</p>



<a name="148749259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/148749259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#148749259">(Nov 28 2018 at 22:34)</a>:</h4>
<p>I wouldn't be surprised, for one reason or another, anyway</p>



<a name="150685521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/150685521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#150685521">(Dec 01 2018 at 14:31)</a>:</h4>
<p>Some notes on two-phase borrows and some potential changes: <a href="https://gist.github.com/matthewjasper/1e48c300e96aaf69e9f56a2d9f969c87" target="_blank" title="https://gist.github.com/matthewjasper/1e48c300e96aaf69e9f56a2d9f969c87">https://gist.github.com/matthewjasper/1e48c300e96aaf69e9f56a2d9f969c87</a></p>



<a name="152172869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/152172869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#152172869">(Dec 19 2018 at 10:28)</a>:</h4>
<p><span class="user-mention" data-user-id="116083">@pnkfelix</span> on the topic of implementing 2PB via rewriting, I see that <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3089aa28872013534beafb0682edd57f" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=3089aa28872013534beafb0682edd57f">this example compiles</a>:</p>
<div class="codehilite"><pre><span></span><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">vec</span><span class="o">!</span><span class="p">[];</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">vec</span><span class="o">!</span><span class="p">[];</span><span class="w"></span>
<span class="w">    </span><span class="n">x</span><span class="p">.</span><span class="n">push</span><span class="p">((</span><span class="w"></span>
<span class="w">        </span><span class="p">{</span><span class="w"></span>
<span class="w">            </span><span class="k">if</span><span class="w"> </span><span class="kc">false</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">x</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="w">            </span><span class="mi">22</span><span class="w"></span>
<span class="w">        </span><span class="p">},</span><span class="w"></span>
<span class="w">        </span><span class="n">x</span><span class="p">.</span><span class="n">len</span><span class="p">(),</span><span class="w"></span>
<span class="w">    </span><span class="p">));</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<p>though I suspect that <em>this one</em> doesn't occur a lot in the wild =)</p>



<a name="152172887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/152172887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#152172887">(Dec 19 2018 at 10:28)</a>:</h4>
<p>(afk now)</p>



<a name="152174894"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/152174894" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#152174894">(Dec 19 2018 at 11:09)</a>:</h4>
<p>hmm. look at this: <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=b997316b973891850c7d457ac79b3ac5" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=b997316b973891850c7d457ac79b3ac5">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=b997316b973891850c7d457ac79b3ac5</a></p>



<a name="152174954"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/152174954" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#152174954">(Dec 19 2018 at 11:10)</a>:</h4>
<p>oh wait, duh</p>



<a name="152174957"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/152174957" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#152174957">(Dec 19 2018 at 11:10)</a>:</h4>
<p>that isn't surprising at all</p>



<a name="152175040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/two-phase%20borrows%20with%20existing%20loans/near/152175040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> pnkfelix <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/two-phase.20borrows.20with.20existing.20loans.html#152175040">(Dec 19 2018 at 11:12)</a>:</h4>
<p>(had to lift the value being borrowed into a separate nameable thing to observe the effect, <a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=b2c11f234815fe0b3d44d233aaff2f28" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2015&amp;gist=b2c11f234815fe0b3d44d233aaff2f28">this way</a>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>